<template>
    <div id="under-net-order" class="order-content">
        <div class="top" style="width: 100%; overflow: auto">
            <el-row class="row-height top-row" style="border-bottom: 1px solid #c9c9c9">
                <el-col :key="renderUUID" :span="8" class="col-box" style="border-right: 1px solid #c9c9c9">
                    <h3 class="title">风控指令:</h3>
                    <el-form label-width="110px" size="small">
                        <el-row class="form-row">
                            <el-col>
                                <el-form-item label="外部指令序号:"
                                    ><el-input :value="instruction.outerOrderCode" disabled size="mini"></el-input
                                ></el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="form-row">
                            <!-- <el-col :span="12">
                                <el-form-item label="下单模式:">
                                    <el-select v-model="instruction.directMode" size="mini">
                                        <el-option
                                            v-for="i in directModeSelectData"
                                            :key="i.dictKey"
                                            :label="i.dictKey + ' ' + i.dictKeyName"
                                            :value="i.dictKey"
                                        >
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col> -->
                            <el-col :span="12">
                                <el-form-item label="指令类型:">
                                    <el-select v-model="instruction.instructionType" size="mini">
                                        <el-option
                                            v-for="i in instructionTypeSelectData"
                                            :key="i.dictKey"
                                            :label="i.dictKey + ' ' + i.dictKeyName"
                                            :value="i.dictKey"
                                        >
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-divider></el-divider>
                        <BondTradingOrder
                            v-if="instruction.instructionType === '1'"
                            @getRiskForm="getRiskForm"
                            :show="show"
                            @getStockName="getStockName"
                        />
                        <RepurchaseOrder
                            v-else-if="instruction.instructionType === '2'"
                            @getRiskForm="getRiskForm"
                            :show="show"
                            @getStockName="getStockName"
                        />
                        <DepositOrder
                            v-else-if="instruction.instructionType === '3'"
                            @getRiskForm="getRiskForm"
                            :show="show"
                            @getStockName="getStockName"
                        />
                        <ExchangeOrder
                            v-else-if="instruction.instructionType === '4'"
                            @getRiskForm="getRiskForm"
                            :show="show"
                            @getStockName="getStockName"
                            :showStock="showStock"
                        />
                        <OneBondOrder
                            v-else-if="instruction.instructionType === '5'"
                            @getRiskForm="getRiskForm"
                            :show="show"
                            @getStockName="getStockName"
                        />
                        <FuturesOrder
                            v-else-if="instruction.instructionType === '6'"
                            @getRiskForm="getRiskForm"
                            :show="show"
                            @getStockName="getStockName"
                        />
                        <ExchangeBulkOrder
                            v-else-if="instruction.instructionType === '7'"
                            @getRiskForm="getRiskForm"
                            :show="show"
                            @getStockName="getStockName"
                        />
                        <CwOpenFundOrder
                            v-else-if="instruction.instructionType === '8'"
                            @getRiskForm="getRiskForm"
                            :show="show"
                            @getStockName="getStockName"
                        />
                        <UnderNetOrder
                            v-else-if="instruction.instructionType === '9'"
                            @getRiskForm="getRiskForm"
                            :show="show"
                            @getStockName="getStockName"
                        />

                        <el-divider></el-divider>
                        <el-row class="form-row">
                            <el-col>
                                <el-form-item label="备注:"><el-input v-model="instruction.remark" size="mini"></el-input></el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="form-row" style="float: right">
                            <el-select style="width: 150px; margin-right: 10px" clearable v-model="instruction.directMode" size="mini">
                                <el-option label="有序从严控制" value="0">有序从严控制</el-option>
                                <el-option label="有序非从严控制" value="1">有序非从严控制</el-option>
                                <el-option label="无序从严控制" value="2">无序从严控制</el-option>
                                <el-option label="无序非从严控制" value="3">无序非从严控制</el-option>
                            </el-select>
                            <el-button v-authCode="B_0039" @click="handleRemake" size="mini">重置</el-button>
                            <el-button v-authCode="B_0041" @click="handleSubmit('1')" type="primary" size="mini">试算</el-button>
                            <el-button v-authCode="B_0040" @click="handleSubmit('2')" type="primary" size="mini">下单</el-button>
                        </el-row>
                    </el-form>
                </el-col>
                <el-col :span="16" class="col-box security-box">
                    <h3 class="title">选择产品:</h3>
                    <el-row class="form-row" style="margin-bottom: 10px">
                        <el-col :span="10">
                            <span class="title">产品序号:</span>
                            <RiskEntryInput @set-entry-data="getEntryslist" :returnDatas="fundCode" style="display: inline-block" />
                            <!-- <el-select v-model="fundCode" @change="handleFundCodeChange" filterable size="mini">
                                <el-option
                                    v-for="i in fundCodeSelectData"
                                    :key="i.fundCode"
                                    :label="i.fundCode + ' ' + i.fundNameSt"
                                    :value="i.fundCode"
                                >
                                </el-option>
                            </el-select> -->
                        </el-col>
                        <el-col :span="10">
                            <span class="title">组合编码:</span>
                            <el-select v-model="fundAccountCode" size="mini" multiple collapse-tags>
                                <el-option
                                    v-for="i in computedFundAccountCodeSelectData"
                                    :key="i.fundAccountCode"
                                    :label="i.fundAccountCode + ' ' + i.fundAccountName"
                                    :value="i.fundAccountCode"
                                >
                                </el-option>
                            </el-select>
                        </el-col>
                        <el-button type="primary" size="mini" @click="handleBatchFund">添加</el-button>
                    </el-row>
                    <vxe-table :data="selectFundDataSource" border size="mini" style="width: 100%" header-align="center">
                        <vxe-column title="操作">
                            <template slot-scope="scope">
                                <el-button icon="el-icon-close" size="mini" @click="handleDelFund(scope.row)" type="primary"></el-button>
                            </template>
                        </vxe-column>
                        <vxe-column field="fundCode" title="产品代码" show-overflow></vxe-column>
                        <vxe-column field="fundNameSt" title="产品简称" show-overflow>
                            <template slot-scope="scope">
                                <span>{{ scope.row.fundNameSt || '--' }}</span>
                            </template>
                        </vxe-column>
                        <vxe-column field="assetCode" title="资产单元编号" show-overflow v-if="SHOW_SECURITY">
                            <template slot-scope="scope">
                                <span>{{ scope.row.assetCode || '--' }}</span>
                            </template>
                        </vxe-column>
                        <vxe-column field="assetName" title="资产单元名称" show-overflow v-if="SHOW_SECURITY">
                            <template slot-scope="scope">
                                <span>{{ scope.row.assetName || '--' }}</span>
                            </template>
                        </vxe-column>
                        <vxe-column field="fundAccountNo" title="组合序号" show-overflow>
                            <template slot-scope="scope">
                                <span>{{ scope.row.fundAccountNo || '--' }}</span>
                            </template>
                        </vxe-column>
                        <vxe-column field="fundAccountCode" title="组合编码" show-overflow>
                            <template slot-scope="scope">
                                <span>{{ scope.row.fundAccountCode || '--' }}</span>
                            </template>
                        </vxe-column>
                        <vxe-column field="fundAccountName" title="组合名称" show-overflow>
                            <template slot-scope="scope">
                                <span>{{ scope.row.fundAccountName || '--' }}</span>
                            </template>
                        </vxe-column>
                    </vxe-table>
                    <!-- <risk-table :msg="positionsListMsg" @handleBtn="handleDelFund"></risk-table> -->
                </el-col>
            </el-row>
        </div>
        <el-row class="row-height bottom-row">
            <el-col class="col-box">
                <h3 class="title">
                    <el-row>
                        <el-col :span="3">风控结果:<status-tag :code="riskResult"></status-tag></el-col>
                        <el-col :span="6">
                            <span>试算/下单时间: </span>
                            <span style="color: red">{{ calcTime }}</span>
                        </el-col>
                        <el-col :span="5">
                            <span>计算耗时: </span>
                            <span style="color: red">{{ takeTime }}</span>
                        </el-col>
                        <el-col :span="4"
                            >条目检查数:
                            <span v-show="riskResListMsg.returnData.data.length" style="color: red">{{
                                riskResListMsg.returnData.data.length
                            }}</span></el-col
                        >
                    </el-row>
                    <el-divider></el-divider>
                </h3>
                <!-- 风控结果表 -->
                <RiskResult :riskResultTable="riskResultTable" :stockInfoPojo="stockInfoPojo" />
            </el-col>
        </el-row>
    </div>
</template>

<script lang="ts">
import { Component, Vue, Watch } from 'vue-property-decorator';
import RiskTable from '@/common/components/risk-table.vue';
import DictionConstUtil, { SGU_CACHE, objToArr } from '@/utils/diction-const-util';
import Invest from '@/common/dict/invest';
import { UUID, NumberToWords, getConfigItem } from '@/utils/tools';
import StatusTag from '../status-tag.vue';
import BranchTag from '../branch-tag.vue';
import RiskResult from '../risk-result.vue';

import { getUser } from '@/utils/user-util';
import BondTradingOrder from '../batch-invest/order-form/bond-trading-order.vue';
import RepurchaseOrder from '../batch-invest/order-form/repurchase-order.vue';
import DepositOrder from '../batch-invest/order-form/deposit-order.vue';
import ExchangeOrder from '../batch-invest/order-form/exchange-order.vue';
import OneBondOrder from '../batch-invest/order-form/one-bond-order.vue';
import FuturesOrder from '../batch-invest/order-form/futures-order.vue';
import ExchangeBulkOrder from '../batch-invest/order-form/exchange-bulk-order.vue';
import CwOpenFundOrder from '../batch-invest/order-form/cw-open-fund-order.vue';
import UnderNetOrder from '../batch-invest/order-form/under-net-order.vue';
import RiskEntryInput from '@/common/components/risk-entry-input.vue';
import RiskInputNumber from '@/pages/risk-measure/components/risk-input-number.vue';

@Component({
    name: 'ExchangeBatch',
    components: {
        RiskTable,
        StatusTag,
        BranchTag,
        RiskResult,
        BondTradingOrder,
        RepurchaseOrder,
        DepositOrder,
        ExchangeOrder,
        OneBondOrder,
        FuturesOrder,
        ExchangeBulkOrder,
        CwOpenFundOrder,
        UnderNetOrder,
        RiskEntryInput,
    },
})
export default class ExchangeBatch extends Vue {
    SHOW_SECURITY = getConfigItem('SHOW_SECURITY');

    // 风控指令表单
    instruction = {
        instructionType: '1',
        // directMode: '1',
        outerOrderCode: '自动生成',
        remark: '',
        // strict: '0',
        directMode: '0',
    };

    // 证券信息相关
    stockMessageMsg = { url: '/baseInfomation/stockCode/', returnData: {} };

    // 产品信息相关
    positionsListMsg = {
        // url: '/baseInfomation/stocks/',
        returnData: { data: [], total: 0 },
        dataKey: 'data',
        title: [
            {
                name: '操作',
                type: 'btn',
                btns: [{ title: '删除', type: 'primary', icon: 'el-icon-close' }],
                width: 80,
            },
            { name: '产品代码', val: 'fundCode' },
            { name: '产品简称', val: 'fundNameSt' },
            { name: '组合序号', val: 'fundAccountNo' },
            { name: '组合编码', val: 'fundAccountCode' },
            { name: '组合名称', val: 'fundAccountName' },
        ],
        height: '200px',
        hidePage: false,
        checked: { on: false, option: false },
    };
    // 风控结果相关
    riskResListMsg = {
        url: '/dataEngine/order/multiOrder',
        returnData: { data: [] },
        dataKey: 'data',
        height: '350px',
        // 隐藏页码
        hidePage: true,
        checked: { on: false, option: false },
    };

    // 产品信息
    fundInfo = {
        fundCode: '',
        fundNameSt: '',
        fundAccountCode: '',
        fundAccountNo: '',
        fundAccountName: '',
        assetCode: '',
        assetName: '',
    };

    // 风控结果表数据
    riskResultTable: any[] = [];

    stockInfoPojo: any = {};

    // 显示证券代码选择弹框
    private stockCodeDialog: boolean = false;

    // 图标dom
    private iconDom: any = null;

    private tableKey: number = 1;

    private Invest: any = new Invest();
    private DictionConstUtil: any = new DictionConstUtil();

    // 下单模式下拉数据
    private directModeSelectData: any[] = [];

    // 指令类型下拉数据
    private instructionTypeSelectData: any[] = [];

    // 已添加的产品
    private selectFundDataSource: any[] = [];

    // 产品序号
    private fundCode: string = '';

    // 组合编码
    private fundAccountCode: string[] = [];
    private fundCodeSelectData: any[] = []; // 产品序号下拉框数据
    private fundAccountCodeSelectData: any[] = []; // 组合编码下拉框数据

    private renderUUID: any;

    private flag: boolean = false;

    // 子组件表单
    private instructionForm = {};

    calcTime: string = ''; // 下单/试算时间

    takeTime: string | number = ''; // 计算耗时

    riskResult: string | number = ''; // 风控结果

    entryType = {}; // 风险类型字典

    compareDirection = {}; // 比较方向字典

    show: boolean = true;

    // 是否显示证券代码
    showStock: boolean = true;

    async mounted() {
        // 获取下单模式下拉数据
        // this.directModeSelectData = objToArr(DictionConstUtil.DirectMode);
        // 获取指令类型下拉数据
        this.instructionTypeSelectData = objToArr(this.Invest.instructionType);
        // 获取产品信息 (产品序号下拉框数据)
        this.fundCodeSelectData = await SGU_CACHE('FundInfo', '/fundInfo/list', []);
        // 获取组合编码下拉框数据
        let arr = await SGU_CACHE('FundAccount', '/fundInfo/accounts', []);
        arr.forEach(item => {
            this.fundAccountCodeSelectData[item.fundCode] = item.fundAccounts;
        });
        // 获取风险类型字典
        this.entryType = this.Invest.entryType;
        // 获取比较方向字典
        this.compareDirection = this.Invest.CompareDirection;
        // 重新渲染表格
        // this.changeData();
    }

    // 组合编码下拉框计算属性
    get computedFundAccountCodeSelectData() {
        return this.fundAccountCodeSelectData[this.fundCode] || [];
    }

    getEntryslist(val: any) {
        this.fundCode = val;
        this.handleFundCodeChange();
    }

    // 产品代码变化
    handleFundCodeChange() {
        this.fundAccountCode = [];
    }

    getStockName(val: any) {
        this.stockInfoPojo = val;
    }

    // 清除已选基金序号
    private handleDelFund(row: any) {
        this.selectFundDataSource = this.selectFundDataSource.filter(item => item.fundAccountNo !== row.fundAccountNo);
    }

    // 添加产品
    private handleBatchFund() {
        this.fundInfo.fundCode = this.fundCode;
        // 获取选中的产品信息
        this.fundCodeSelectData.forEach(ele => {
            if (ele.fundCode === this.fundCode) {
                this.fundInfo.fundNameSt = ele.fundNameSt;
            }
        });
        // 获取选中的产品编码信息
        this.fundAccountCodeSelectData[this.fundCode].forEach(ele => {
            this.fundAccountCode.forEach(item => {
                if (ele.fundAccountCode === item) {
                    this.fundInfo.fundAccountCode = item;
                    this.fundInfo.fundAccountNo = ele.fundAccountNo;
                    this.fundInfo.fundAccountName = ele.fundAccountName;
                    this.fundInfo.assetCode = ele.assetCode;
                    this.fundInfo.assetName = ele.assetName;
                }
            });
        });
        // 勾选组合编码
        let selectedFundAccountNo: any[] = [];
        for (let i = 0; i < this.fundAccountCode.length; i++) {
            if (
                this.selectFundDataSource.find(item => item.fundCode === this.fundInfo.fundCode && item.fundAccountCode === this.fundAccountCode[i])
            ) {
                continue;
            }
            this.selectFundDataSource.unshift({
                key: this.fundInfo.fundCode + '-' + this.fundAccountCode[i],
                fundAccountCode: this.fundAccountCode[i],
                fundCode: this.fundInfo.fundCode,
                fundNameSt: this.fundInfo.fundNameSt,
                fundAccountName: this.fundInfo.fundAccountName,
                fundAccountNo: this.fundInfo.fundAccountNo,
                assetCode: this.fundInfo.assetCode,
                assetName: this.fundInfo.assetName,
            });
        }
        this.positionsListMsg.returnData.data = this.selectFundDataSource;
        this.positionsListMsg.returnData.total = this.selectFundDataSource.length;
    }

    // 批量指令组装
    createBatchInstruction(collective, factInstruction, orderType) {
        let requestId = 'reb' + UUID() + '-' + new Date().getTime();
        let instructionPojo = {
            requestId: requestId,
            instructionType: collective.instructionType,
            orderType: orderType,
            // directMode: collective.directMode,
            multiType: '1',
            outOrderBatchCode: UUID() + '-' + new Date().getTime(),
            tradeUser: getUser().userCode,
            instList: [],
            cancelType: factInstruction.cancelType,
            directMode: '',
        };
        if (orderType === '1') {
            // instructionPojo.strict = this.instruction.strict;
            instructionPojo.directMode = this.instruction.directMode;
        }
        let selectFundDataSource = this.selectFundDataSource;
        let instList = [];
        for (let i = 0; i < selectFundDataSource.length; i++) {
            instList.push(
                JSON.stringify({
                    orderType: orderType,
                    requestId: requestId,
                    instructionType: collective.instructionType,
                    outerOrderCode: 'eb' + UUID() + String(i) + '-' + new Date().getTime(),
                    fundCode: selectFundDataSource[i].fundCode,
                    fundAccountCode: selectFundDataSource[i].fundAccountCode,
                    remark: collective.remark,
                    ...factInstruction,
                })
            );
        }
        instructionPojo.instList = instList;
        return instructionPojo;
    }

    // 转表格筛选下拉框数据
    objToArr(param) {
        let list = [];
        for (let key in param) {
            list.push({ label: param[key], value: key });
        }
        return list;
    }

    // 校验提交参数
    verifyInstructionPamessageram(instruction, instructionType) {
        console.log(instruction);

        if (!this.selectFundDataSource || this.selectFundDataSource.length === 0) {
            this.yh_message_error('至少添加一个基金投资组合');
            return false;
        }
        if (instructionType === '1') {
            if (!instruction.orderUser) {
                this.yh_message_error('下单人不可为空');
                return false;
            }
            if (!instruction.marketCode) {
                this.yh_message_error('市场序号不可为空');
                return false;
            }
            if (!instruction.orderDirection) {
                this.yh_message_error('订单方向不可为空');
                return false;
            }
            if (instruction.orderPrice === undefined) {
                this.yh_message_error('指令价格不可为空');
                return false;
            }
            if (instruction.orderAmount === undefined) {
                this.yh_message_error('指令数量不可为空');
                return false;
            }
            if (instruction.orderBalance === undefined) {
                this.yh_message_error('指令金额不可为空');
                return false;
            }
            if (!instruction.orderLevel) {
                this.yh_message_error('指令优先级不可为空');
                return false;
            }
        } else if (instructionType === '2') {
            if (!instruction.orderUser) {
                this.yh_message_error('下单人不可为空');
                return false;
            }
            if (!instruction.marketCode) {
                this.yh_message_error('市场序号不可为空');
                return false;
            }
            if (!instruction.investType) {
                this.yh_message_error('投资类型不可为空');
                return false;
            }
            if (!instruction.orderDirection) {
                this.yh_message_error('订单方向不可为空');
                return false;
            }
            if (instruction.orderPrice === undefined) {
                this.yh_message_error('指令价格不可为空');
                return false;
            }
            if (instruction.orderAmount === undefined) {
                this.yh_message_error('指令数量不可为空');
                return false;
            }
            if (instruction.orderBalance === undefined) {
                this.yh_message_error('指令金额不可为空');
                return false;
            }
            if (!instruction.orderLevel) {
                this.yh_message_error('指令优先级不可为空');
                return false;
            }
            if (!instruction.firstSettleDate) {
                this.yh_message_error('首次交割日不可为空');
                return false;
            }
            if (!instruction.endSettleDate) {
                this.yh_message_error('到期交割日不可为空');
                return false;
            }
            if (!instruction.clearSpeed) {
                this.yh_message_error('清算速度不可为空');
                return false;
            }
            if (!instruction.settleType) {
                this.yh_message_error('结算方式不可为空');
                return false;
            }
            if (!instruction.repoDay) {
                this.yh_message_error('回购天数不可为空');
                return false;
            }
            if (instruction.interest !== 0 && !instruction.interest) {
                this.yh_message_error('利息金额不可为空');
                return false;
            }
        } else if (instructionType === '3') {
            if (!instruction.orderUser) {
                this.yh_message_error('下单人不可为空');
                return false;
            }
            if (!instruction.marketCode) {
                this.yh_message_error('市场序号不可为空');
                return false;
            }
            if (!instruction.orderDirection) {
                this.yh_message_error('订单方向不可为空');
                return false;
            }
            if (instruction.orderBalance === undefined) {
                this.yh_message_error('指令金额不可为空');
                return false;
            }
            if (!instruction.orderLevel) {
                this.yh_message_error('指令优先级不可为空');
                return false;
            }
            if (!instruction.bankCode) {
                this.yh_message_error('银行总行不可为空');
                return false;
            }
            if (!instruction.depositStartDate) {
                this.yh_message_error('起息日不可为空');
                return false;
            }
            if (instruction.depositType === '2' && instruction.noticeType === '1' && !instruction.noticeDays) {
                this.yh_message_error('通知天数不可为空');
                return false;
            }

            if (!instruction.mutureDate && instruction.noticeType !== '1') {
                this.yh_message_error('到期日不可为空');
                return false;
            }
            if (!instruction.depositLimitTime) {
                this.yh_message_error('存款期限不可为空');
                return false;
            }
            if (!instruction.depositRate) {
                this.yh_message_error('存款利率不可为空');
                return false;
            }
            if (!instruction.depositType) {
                this.yh_message_error('存款类型不可为空');
                return false;
            }
        } else if (instructionType === '4') {
            if (!instruction.orderUser) {
                this.yh_message_error('下单人不可为空');
                return false;
            }
            if (!instruction.investType) {
                this.yh_message_error('投资类型不可为空');
                return false;
            }
            if (!instruction.marketCode) {
                this.yh_message_error('市场序号不可为空');
                return false;
            }
            if (!instruction.orderDirection) {
                this.yh_message_error('订单方向不可为空');
                return false;
            }
            if (instruction.orderPrice === undefined) {
                this.yh_message_error('指令价格不可为空');
                return false;
            }
            if (instruction.orderAmount === undefined) {
                this.yh_message_error('指令数量不可为空');
                return false;
            }
            if (instruction.orderBalance === undefined) {
                this.yh_message_error('指令金额不可为空');
                return false;
            }
            if (!instruction.orderLevel) {
                this.yh_message_error('指令优先级不可为空');
                return false;
            }
        } else if (instructionType === '5') {
            if (!instruction.orderDirection) {
                this.yh_message_error('订单方向不可为空');
                return false;
            }
            if (!instruction.orderUser) {
                this.yh_message_error('下单人不可为空');
                return false;
            }
            if (!instruction.investType) {
                this.yh_message_error('投资类型不可为空');
                return false;
            }
            if (!instruction.reportCode) {
                this.yh_message_error('申报代码不可为空');
                return false;
            }
            if (!instruction.marketCode) {
                this.yh_message_error('市场序号不可为空');
                return false;
            }
            if (instruction.orderPrice === undefined) {
                this.yh_message_error('指令价格不可为空');
                return false;
            }
            if (instruction.orderAmount === undefined) {
                this.yh_message_error('指令数量不可为空');
                return false;
            }
            if (instruction.orderBalance === undefined) {
                this.yh_message_error('指令金额不可为空');
                return false;
            }
            if (!instruction.orderLevel) {
                this.yh_message_error('指令优先级不可为空');
                return false;
            }
            if (!instruction.fee) {
                this.yh_message_error('手续费不能为空');
                return false;
            }
            if (!instruction.firstSettleDate) {
                this.yh_message_error('首次交割日不能为空');
                return false;
            }
            if (!instruction.endSettleDate) {
                this.yh_message_error('到期交割日不能为空');
                return false;
            }
        } else if (instructionType === '6') {
            if (!instruction.orderDirection) {
                this.yh_message_error('订单方向不可为空');
                return false;
            }
            if (!instruction.orderUser) {
                this.yh_message_error('下单人不可为空');
                return false;
            }
            if (!instruction.investType) {
                this.yh_message_error('投资类型不可为空');
                return false;
            }
            if (!instruction.reportCode) {
                this.yh_message_error('申报代码不可为空');
                return false;
            }
            if (!instruction.marketCode) {
                this.yh_message_error('市场序号不可为空');
                return false;
            }
            if (instruction.orderPrice === undefined) {
                this.yh_message_error('指令价格不可为空');
                return false;
            }
            if (instruction.orderAmount === undefined) {
                this.yh_message_error('指令数量不可为空');
                return false;
            }
            if (instruction.orderBalance === undefined) {
                this.yh_message_error('指令金额不可为空');
                return false;
            }
            if (!instruction.orderLevel) {
                this.yh_message_error('指令优先级不可为空');
                return false;
            }
        } else if (instructionType === '7') {
            if (!instruction.orderDirection) {
                this.yh_message_error('订单方向不可为空');
                return false;
            }
            if (!instruction.orderUser) {
                this.yh_message_error('下单人不可为空');
                return false;
            }
            if (!instruction.investType) {
                this.yh_message_error('投资类型不可为空');
                return false;
            }
            if (!instruction.reportCode) {
                this.yh_message_error('申报代码不可为空');
                return false;
            }
            if (!instruction.marketCode) {
                this.yh_message_error('市场序号不可为空');
                return false;
            }
            if (instruction.orderPrice === undefined) {
                this.yh_message_error('指令价格不可为空');
                return false;
            }
            if (instruction.orderAmount === undefined) {
                this.yh_message_error('指令数量不可为空');
                return false;
            }
            if (instruction.orderBalance === undefined) {
                this.yh_message_error('指令金额不可为空');
                return false;
            }
            // if (!instruction.orderPrice) {
            //     this.yh_message_error('指令价格不可为空');
            //     return false;
            // }
            // if (!instruction.orderAmount) {
            //     this.yh_message_error('指令数量不可为空');
            //     return false;
            // }
            // if (!instruction.orderBalance && instruction.orderBalance !== 0) {
            //     this.yh_message_error('指令金额不可为空');
            //     return false;
            // }
            if (!instruction.orderLevel) {
                this.yh_message_error('指令优先级不可为空');
                return false;
            }
        } else if (instructionType === '8') {
            if (!instruction.orderDirection) {
                this.yh_message_error('订单方向不可为空');
                return false;
            }
            if (!instruction.orderUser) {
                this.yh_message_error('下单人不可为空');
                return false;
            }
            if (!instruction.investType) {
                this.yh_message_error('投资类型不可为空');
                return false;
            }
            if (!instruction.reportCode) {
                this.yh_message_error('申报代码不可为空');
                return false;
            }
            if (!instruction.marketCode) {
                this.yh_message_error('市场序号不可为空');
                return false;
            }
            if (instruction.orderAmount === undefined) {
                this.yh_message_error('指令数量不可为空');
                return false;
            }
            if (instruction.orderBalance === undefined) {
                this.yh_message_error('指令金额不可为空');
                return false;
            }
            if (!instruction.orderLevel) {
                this.yh_message_error('指令优先级不可为空');
                return false;
            }
            if (!instruction.bulkType) {
                this.yh_message_error('巨额赎回标志不可为空');
                return false;
            }
        } else if (instructionType === '9') {
            if (!instruction.orderDirection) {
                this.yh_message_error('订单方向不可为空');
                return false;
            }
            if (!instruction.orderUser) {
                this.yh_message_error('下单人不可为空');
                return false;
            }
            if (!instruction.investType) {
                this.yh_message_error('投资类型不可为空');
                return false;
            }
            if (!instruction.reportCode) {
                this.yh_message_error('申报代码不可为空');
                return false;
            }
            if (!instruction.marketCode) {
                this.yh_message_error('市场序号不可为空');
                return false;
            }
            if (instruction.orderPrice === undefined) {
                this.yh_message_error('指令价格不可为空');
                return false;
            }
            if (instruction.orderAmount === undefined) {
                this.yh_message_error('指令数量不可为空');
                return false;
            }
            if (instruction.orderBalance === undefined) {
                this.yh_message_error('指令金额不可为空');
                return false;
            }
            if (!instruction.orderLevel) {
                this.yh_message_error('指令优先级不可为空');
                return false;
            }
            if (!instruction.applyAmount) {
                this.yh_message_error('网下申购金额不可为空');
                return false;
            }
            if (!instruction.winningRate) {
                this.yh_message_error('预估中签率不可为空');
                return false;
            }
        }
        return true;
    }

    // filterEntryType({ value, row, column }) {
    //   return row.entryType == value;
    // }

    // filterThresholdType({ value, row, column }) {
    //   return row.thresholdType == value;
    // }

    // filterHandler({ option, row, column }) {
    //   const property = column['property'];
    //   return row[property].includes(option.data);
    // }

    // 重新渲染表格
    changeData() {
        this.$nextTick(() => {
            if (!this.iconDom) {
                this.iconDom = document.querySelectorAll('.vxe-icon--funnel');
                for (let i = 0; i < 6; i++) {
                    this.iconDom[i].className = 'vxe-filter--btn el-icon-search';
                }
            }
            this.tableKey++;
        });
    }

    // 获取指令表单
    private getRiskForm(val) {
        this.instructionForm = val;
    }

    // 重置按钮事件
    handleRemake() {
        this.instruction = {
            instructionType: '1',
            // directMode: '1',
            outerOrderCode: '自动生成',
            remark: '',
            // strict: '',
            directMode: '0',
        };
        this.renderUUID = UUID();
    }

    // 提交事件
    handleSubmit(orderType: string) {
        this.flag = true;
        console.log(this.instructionForm);

        // 校验参数规则
        if (!this.verifyInstructionPamessageram(this.instructionForm, this.instruction.instructionType)) {
            return;
        }
        let instruction = this.createBatchInstruction(this.instruction, this.instructionForm, orderType);
        // 获取当前提交时间 (试算/下单时间)
        // 补零
        let fillZero = n => {
            let result = n.toString().length === 1 ? '0' + n : n;
            return result;
        };
        // 时间戳转换 yyyy-MM-dd
        let formatTime = (t = new Date()) => {
            let d = new Date(t);
            let year = d.getFullYear();
            let month = d.getMonth() + 1;
            let date = d.getDate();
            let hours = d.getHours();
            let minutes = d.getMinutes();
            let seconds = d.getSeconds();
            let result = `${year}-${fillZero(month)}-${fillZero(date)} ${fillZero(hours)}:${fillZero(minutes)}:${fillZero(seconds)}`;
            return result;
        };
        // 计算耗时
        let start = window.performance.now();
        this.calcTime = formatTime(new Date());
        // 提交指令 => 获取风控结果
        this.$axios.post(this.riskResListMsg.url, instruction).then((res: any) => {
            this.yh_message_success('指令信息提交成功');
            // 风控结果
            this.riskResult = res.thresholdType;
            // 计算耗时
            let end = window.performance.now();
            this.takeTime = ((end - start) / 1000).toFixed(3) + '秒';

            let data = res.resultList || [];

            // 根据产品代码 匹配产品名称
            data.forEach(ele => {
                ele.requestId = res.requestId;
                // 风险类型
                ele.entryType2 = this.entryType[ele.entryType];
                // 比较方向
                ele.compareType2 = this.compareDirection[ele.compareType];

                for (let i = 0; i < this.fundCodeSelectData.length; i++) {
                    const item = this.fundCodeSelectData[i];
                    if (ele.fundCode === item.fundCode) {
                        ele.fundNameSt = item.fundNameSt;
                    }
                }
            });
            this.$set(this.riskResListMsg.returnData, 'data', data);
            this.riskResultTable = this.riskResListMsg.returnData.data;
        });
    }
}
</script>

<style lang="scss" scoped>
@import '@/pages/risk-measure/style/measure';

#under-net-order {
    width: 100%;
    height: 100vh;
    min-height: 600px;
    // min-width: 1200px;
    .title {
        color: #575757;
        margin-right: 10px;
    }
    .el-divider--horizontal {
        height: 0.5px;
    }
    .row-height {
        // height: 50%;
        // min-height: 450px;
        .col-box {
            // height: 100%;
            padding: 10px 5px;
            .el-divider {
                margin: 0;
                margin-top: 5px;
            }
            .form-row,
            .form-row2 {
                margin-top: 3px;
                .el-form-item--small {
                    margin: 0;
                    & /deep/ .el-form-item__label {
                        color: #575757;
                    }
                    & /deep/ .el-input__inner {
                        height: 28px;
                        line-height: 28px;
                    }
                }
            }

            .form-row2 {
                .row2-div {
                    position: relative;
                    .row-2 {
                        position: absolute;
                        top: 0;
                        left: 70px;
                    }
                }
            }
        }
        .security-box {
            .form-row {
                .el-form-item--small {
                    & /deep/ .el-input__inner {
                        background: #fff;
                        color: #575757;
                    }
                }
                .el-input {
                    display: inline-table;
                    /deep/ .el-input-group__append {
                        padding: 0 10px !important;
                    }
                }
            }
        }
        .left-p {
            position: absolute;
            right: 0px;
            top: 3px;
            height: 28px;
            display: flex;
            align-items: center;
            .el-icon-search {
                color: #fff;
            }
        }
    }
}
</style>
